package yadong.example.code.jaxb;

import java.io.StringWriter;
import java.util.ArrayList;

import javax.xml.XMLConstants;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;

import org.xml.sax.SAXException;


public class TestProfileXml {

	public static void main(String[] args) {
		Doc doc = new Doc();
		
		ProfileXml oProfileXml = new ProfileXml();

		
		oProfileXml.setEntityId("xyz");
		oProfileXml.setFlavorType("xyz");
		oProfileXml.setAlertMessage("xyz");
		oProfileXml.setExipred("dd");
		oProfileXml.setPullQuote("xyz");
		oProfileXml.setOffline("xyz");
		oProfileXml.setTitle("xyz");
		oProfileXml.setEditorsPick("xyz");
		oProfileXml.setFullReviewUrl("xyz");
		oProfileXml.setAverageReaderRating("xyz");
		oProfileXml.setReaderReviewCount("xyz");
		oProfileXml.setLatitude("xyz");
		oProfileXml.setLongitude("xyz");
		oProfileXml.setAddress("xyz");
		oProfileXml.setCity("xyz");
		oProfileXml.setState("xyz");
		oProfileXml.setZip("xyz");
		oProfileXml.setPhone("xyz");
		oProfileXml.setMakeReservationDescriptionText("xyz");
		oProfileXml.setMakeReservationText("xyz");
		oProfileXml.setMakeReservationUrl("xyz");
		oProfileXml.setPrice("xyz");
		oProfileXml.setTheaterTicketDescriptionText("xyz");
		oProfileXml.setTheaterTicketText("xyz");
		oProfileXml.setTheaterTicketUrl("xyz");
		oProfileXml.setUpcomingVenueTitle("xyz");
		oProfileXml.setUpcomingVenueId("xyz");
		oProfileXml.setWebSiteUrl("xyz");
		oProfileXml.setCriticRating("xyz");
		oProfileXml.setMyRating("xyz");
		oProfileXml.setOnBestXYZ("xyz");
		oProfileXml.setOnPlayListCount("xyz");
		oProfileXml.setReaderReviewRating("xyz");
		oProfileXml.setTomSietsemaRating("xyz");
		oProfileXml.setAdmission("xyz");
		oProfileXml.setAtmosphare("xyz");
		oProfileXml.setBarFeature("xyz");
		oProfileXml.setDecibelComment("xyz");
		oProfileXml.setDiningGuideImageUrl("xyz");
		oProfileXml.setDiningGuideImageDisplayText("xyz");
		oProfileXml.setDiningGuideImageDisplayImage("xyz");
		oProfileXml.setDirector("xyz");
		oProfileXml.setGenre("xyz");
		oProfileXml.setDistribution("xyz");
		oProfileXml.setHours("xyz");
		oProfileXml.setKeywords("xyz");
		oProfileXml.setMealType("xyz");
		oProfileXml.setMenuUrl("xyz");
		oProfileXml.setMpaa("xyz");
		oProfileXml.setNeighborhood("xyz");
		oProfileXml.setNewTrailerExist("xyz");
		oProfileXml.setNickNames("xyz");
		oProfileXml.setNote("xyz");
		oProfileXml.setOverview("xyz");
		oProfileXml.setPhotoByLine("xyz");
		oProfileXml.setPhotoCredit("xyz");
		oProfileXml.setPhotoUrl("xyz");
		oProfileXml.setPosterCaption("xyz");
		oProfileXml.setPosterUrl("xyz");
		oProfileXml.setReleaseDate("xyz");
		oProfileXml.setRuntime("xyz");
		oProfileXml.setStarring("xyz");
		oProfileXml.setStartEndDates("xyz");
		oProfileXml.setStreetViewUrl("xyz");
		oProfileXml.setSubategory("xyz");
		oProfileXml.setTrailerUrl("xyz");
		
		
		oProfileXml.setPrimaryCategory(new Category("xxx"));
		EditorialReview oEditorialReview1= new EditorialReview("xxx");
		EditorialReview oEditorialReview2= new EditorialReview("xxx");
		ArrayList<EditorialReview> x= new ArrayList<EditorialReview>();
		x.add(oEditorialReview1);
		x.add(oEditorialReview2);
		oProfileXml.setEditorialreviews(x);
		
		ReaderReview rr1 = new ReaderReview("xyz");
		ReaderReview rr2 = new ReaderReview("xyz");
		ArrayList<ReaderReview> rrlist= new ArrayList<ReaderReview>();
		rrlist.add(rr1);
		rrlist.add(rr2);		
		oProfileXml.setReaderreviews(rrlist);
		
		SpecialFeature sf1 = new SpecialFeature("xxx");
		SpecialFeature sf2 = new SpecialFeature("yyy");
		SpecialFeature sf3 = new SpecialFeature("zzz");
		ArrayList<SpecialFeature> sflist= new ArrayList<SpecialFeature>();
		sflist.add(sf1);
		sflist.add(sf2);
		sflist.add(sf3);
		oProfileXml.setSpecialFeatures(sflist);
		
		ArrayList<SpecialFeature> largeImageList= new ArrayList<SpecialFeature>();
		largeImageList.add(sf1);
		largeImageList.add(sf2);
		largeImageList.add(sf3);
		oProfileXml.setLargeImageUrls(largeImageList);
		
		ArrayList<Occurrence> occurrences = new ArrayList<Occurrence>();
		Occurrence occ1 = new Occurrence("xxx");
		Occurrence occ2 = new Occurrence("yyy");
		Occurrence occ3 = new Occurrence("zzz");
		occurrences.add(occ1);
		occurrences.add(occ2);
		occurrences.add(occ3);
		oProfileXml.setOccurrences(occurrences);
		
		
		ArrayList<RelatedListing> relatedListings = new ArrayList<RelatedListing>();
		RelatedListing rl1 = new RelatedListing("xxx");
		RelatedListing rl2 = new RelatedListing("yyy");
		relatedListings.add(rl1);
		relatedListings.add(rl2);
		oProfileXml.setRelatedListings(relatedListings);
		
		ArrayList<LocationEvent> locationEvents = new ArrayList<LocationEvent>();
		LocationEvent le1 = new LocationEvent("xxx");
		LocationEvent le2 = new LocationEvent("yyy");
		locationEvents.add(le1);
		locationEvents.add(le2);
		oProfileXml.setLocationEvents(locationEvents);

		ArrayList<TheaterShowTime> tsts = new ArrayList<TheaterShowTime>();
		TheaterShowTime tst1 = new TheaterShowTime("xxx");
		TheaterShowTime tst2 = new TheaterShowTime("yyy");
		tsts.add(tst1);
		tsts.add(tst2);
		oProfileXml.setTheaterShowTimes(tsts);
		
		String[] tags = {"xxx","yyy","zzz"};
		oProfileXml.setTags(tags);
		String[] tagUrls = {"AAA","bbb","CCC"};
		oProfileXml.setTagUrls(tagUrls);
		
		ArrayList<Category> cats = new ArrayList<Category>();
		Category cat1 = new Category("xxx");
		Category cat2 = new Category("yyy");
		Category cat3 = new Category("zzz");
		cats.add(cat1);
		cats.add(cat2);
		cats.add(cat3);
		oProfileXml.setUpcomingVenueCategories(cats);
		
		ArrayList<String> locationPhones = new ArrayList<String>();
		locationPhones.add("phone1");
		locationPhones.add("phone2");
		locationPhones.add("phone3");
		oProfileXml.setLocationPhones(locationPhones);
		
		ArrayList<VenueInfo> vilist = new ArrayList<VenueInfo>();
		vilist.add(new VenueInfo("xxx"));
		vilist.add(new VenueInfo("yyy"));
		vilist.add(new VenueInfo("zzz"));
		oProfileXml.setVenueInfoList(vilist);
		
		String[] dates = {"xxx","bbb","CCC"};
		oProfileXml.setMovieShowTimeDateArray(dates);
		
		
		doc.setProfileXml(oProfileXml);
		JAXBContext context=null;
		try {
			context = JAXBContext.newInstance(Doc.class);
		} catch (JAXBException e) {
			e.printStackTrace();
		}
		Marshaller marshaller=null;
		try {
			marshaller = context.createMarshaller();
			marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
			marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
			SchemaFactory schemaFac = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
			Schema schema = schemaFac.newSchema(ClassLoader.getSystemResource("GOG_PROFILES.xsd"));
			marshaller.setSchema(schema);
		} catch (JAXBException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SAXException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		StringWriter sw = new StringWriter();
		
		try {
			marshaller.marshal(doc, sw);
		} catch (JAXBException e) {
			e.printStackTrace();
		}
		String xmltext = sw.toString();     
		System.out.println(xmltext);
	}

}
